import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login'
import Layout from '@/views/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:articleId',
    name: 'Article',
    component: () => import('@/views/article'),
    props: true // 通过路由传递props参数
  },
  {
    path: '/editUserInfo',
    name: 'EditUserInfo',
    component: () => import('@/views/my/edit-user')
  },
  {
    path: '/friends/:type',
    name: 'Friends',
    component: () => import('@/views/my/friends')
  },
  {
    path: '/myPage/:userId',
    name: 'MyPage',
    component: () => import('@/views/my/my-page')
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    children: [
      {
        path: '', // 默认子路由
        name: 'home',
        component: () => import('@/views/home/index.vue')
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/my')
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
